'use strict';

/**
 * @ngdoc function
 * @name jgappApp.controller:PersonnelTcsqtipCtrl
 * @description
 * # PersonnelTcsqtipCtrl
 * Controller of the jgappApp
 */
angular.module('jgappApp')
    .controller('PersonnelTcsqtipCtrl', function ($scope, $rootScope, openApi, Util, $location, $routeParams, $filter, localStorageService, FormSubmit) {
        var id = $scope.process_id = $routeParams.id
        $scope.submit = function (operationId) {

            // 底部类型end
            var options = {};
            // 流程id
            options.id = id;
            // 根据operationId判断是草稿还是提交
            options.operationId = operationId;
            options.urlParam = openApi.commisionApply;
            options.param = angular.copy($scope.param, {});
            FormSubmit.submit(options,$scope);
        };
        $scope.validate = function () {
            if ($scope.param.relatedModuleName && $scope.param.relatedModuleName !== '无') {
                if (!$scope.param.moduleNo) {
                    Util.Toast("请选择模块编号");
                    return;
                }
            }
            if (!$scope.param.year) {
                Util.Toast("请填写提成年份");
                return;
            }
            if (!$scope.param.month) {
                Util.Toast("请填写提成月份");
                return;
            }
            // if (!$scope.param.bidIncome) {
            //     Util.Toast("请填写收入总额");
            //     return;
            // }
            if ($scope.param.formula) {
                if ($scope.param.formula > 100) {
                    Util.Toast("提成比例应该小于100");
                    return;
                }
            } else {
                // Util.Toast("请填写提成比例");
                // return
            }
            if (!$scope.param.commisionAmount) {
                Util.Toast("请填写提成奖励金额");
                return;
            }
            if (!$scope.validation.passvalidation) {
                Util.Toast($scope.validation.tip);
                return;
            }
            return true;
        }

        // 初始化逻辑,如果是修改页面的话则先从接口请求数据回显，再将缓存中的跳转来源删除，方便页面跳转返回之后的回显
        var init = function () {
            // 获取回显的详细信息
            Util.getDetailData(id, function (data) {
                $scope.param = data;
            });
            // 初始化当前5年的数组
            initYears(5);
        };
        // 初始化5年
        var initYears = function (len) {
            $scope.years = [];
            var date = new Date;
            var year = date.getFullYear();
            while (len > 0) {
                len--;
                $scope.years.push(year + "年");
                year--
            }
        };
        $scope.months = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12].map(function (item, index) {
                return item + "月"
            })
            // 初始化
        init();
    });